﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBA.Data;
using DBA.Data.ADO;
using DBA.Bll;
using DBA.Web.UI;
namespace DBA.Web.ProjectManage
{
    public partial class TeacherProject :AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            Bind(1, null);
        }



        protected void linkBtnSearch_Click(object sender, EventArgs e)
        {
            IDictionary<String, String> dict = new Dictionary<String, String>();
            dict.Add("sp_Name", txtsp_Name.Text.Trim());          
            dict.Add("sp_Money", txtsp_Money.Text.Trim());
            dict.Add("sp_Time", txtsp_Time.Value.Trim());
            dict.Add("sp_EndTime", txtsp_EndTime.Value.Trim());
            dict.Add("sp_Class", txtsp_Class.Text.Trim());
            ViewState["conditions"] = dict;
            Bind(1, dict);
        }

       
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            IDictionary<String, String> dict = null;
            if (ViewState["conditions"] != null)
            {
                dict = (IDictionary<String, String>)ViewState["conditions"];
            }
            Bind(e.NewPageIndex, dict);
        }

        private void Bind(int pageIdx, IDictionary<String, String> dict)
        {
            string sql = "select a.*,b.name,sumYearMoney=(select isnull(SUM(ym_Money),0) from YearMoney b where a.sp_ID=b.sp_ID),  ";
            sql += "sumWsMoney=(select isnull(SUM(ws_Money),0) from WorkSharing b where a.sp_ID=b.sp_ID),attCount=(select count(1) from PorjectAttachment b where a.sp_ID=b.sp_ID) from SinProject a  ";
            sql += " left join EmployeeInfo b on a.sp_person=b.EmployeeID where 1=1 ";         
            
            DataAccessLibrary dal = CommonQuery.DataAccessLibrary;
            dal.ManagerParameter.ClearParameter();         
           
            if (dict != null)
            {
                if (!dict["sp_Name"].ToString().Equals(string.Empty))
                {
                    sql += " and a.sp_Name like '%'+@sp_Name+'%'";
                    dal.ManagerParameter.AddNewInParameter("sp_Name", dict["sp_Name"].ToString());
                }              

                if (!dict["sp_Money"].ToString().Equals(string.Empty))
                {
                    sql += " and a.sp_Money like '%'+@sp_Money+'%'";
                    dal.ManagerParameter.AddNewInParameter("sp_Money", dict["sp_Money"].ToString());
                }

                if (!dict["sp_Class"].ToString().Equals(string.Empty))
                {
                    sql += " and a.sp_Class =@sp_Class";
                    dal.ManagerParameter.AddNewInParameter("sp_Class", dict["sp_Class"].ToString());
                }

                if (!dict["sp_Time"].ToString().Equals(string.Empty))
                {
                    sql += " and a.sp_Time >= @sp_Time";
                    dal.ManagerParameter.AddNewInParameter("sp_Time", dict["sp_Time"].ToString());
                }

                if (!dict["sp_EndTime"].ToString().Equals(string.Empty))
                {
                    sql += " and a.sp_EndTime >= @sp_EndTime";
                    dal.ManagerParameter.AddNewInParameter("sp_EndTime", dict["sp_EndTime"].ToString());
                }
            }

            if (Request.Params["type"] != null)
            {
                if (Request.Params["type"] == "1")//系查看
                {
                    sql += " and b.xi_id=@xi_id";
                    dal.ManagerParameter.AddNewInParameter("xi_id", ServerContext.AdminCurrentUser.Xi_ID);

                }
           
            }
            else//个人查看
            {
                sql += " and b.EmployeeID=@EmployeeID  ";
                dal.ManagerParameter.AddNewInParameter("EmployeeID", ServerContext.AdminCurrentUser.EmployeeID);
            }


            int iCount = 0;

            replData.DataSource = dal.ModifyData.GetPageDataTable("(" + sql + ")", "*", "", "sp_Class,sp_Time DESC,sp_ID DESC", pageIdx, 10, ManagerSQL.PageViewTableType.MixtureTable, ref iCount);
            replData.DataBind();
            AspNetPager1.RecordCount = iCount;

        }

        protected void linkBtnMaskSearch_Click(object sender, EventArgs e)
        {
            //IDictionary<String, String> dict = new Dictionary<String, String>();
            //dict.Add("UserName", txtMaskMemberId.Text.Trim());
            //ViewState["conditions"] = dict;
            //Bind(1, dict);
        }

        protected void linkBtnDeleSelect_Click(object sender, EventArgs e)
        {
          
        }
    }
}